package com.sinodata.bsm.inmp.bean.gab;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import com.sinodata.bsm.common.vo.CollectField;
import com.sinodata.bsm.common.vo.Property;
import com.sinodata.bsm.common.vo.Res;
import com.sinodata.bsm.common.vo.ResPropertyValue;
import com.sinodata.bsm.common.vo.ResPropertyValue.PropValue;

/**
 * <p>
 * Description: 
 * </p>
 *
 * @author wangpeng
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2013-9-5 上午10:00:50          wangpeng        1.0         To create
 * </p>
 *
 * @since 
 * @see     
 */
public class WenshiduBean extends WenshiduParentBean {

    private final static int SIZE = 2;

    private static final Long resTypeId = 6021000205000L;

    /**
     * propertyIdList用于存放所以的指标id
     * 
     * propIndexList用于存放每个指标在该类型上的索引值,和propertyIdList中的值一一对应
     */
    private final static List<Long> propertyIdList = new ArrayList<Long>();
    private final static List<Integer> propIndexList = new ArrayList<Integer>();

    private static final int temperatureIndex = 1;//温度
    private static final int humidityIndex = 2;//湿度

    static {
        //初始化指标值
        for (int i = 1; i <= SIZE; i++) {
            propertyIdList.add(resTypeId * 100 + i);
        }

        //初始化指标在表中的索引
        propIndexList.add(temperatureIndex);
        propIndexList.add(humidityIndex);
    }

    public WenshiduBean(Res res) {

        this.res = res;
        this.deviceNumber = Integer.valueOf(res.getInternalId());

        init();
    }

    private void init() {
        for (int i = 0; i < SIZE; i++) {
            propValueMap.put(propertyIdList.get(i), this.getYcValueFromDataMap(propIndexList.get(i)));
        }
    }

    @Override
    public ResPropertyValue getPropertyValue() {
        ResPropertyValue value = new ResPropertyValue();
        value.setResId(res.getId());
        value.setTaskId(-2L);
        value.setTemporary(false);
        value.setTime(Calendar.getInstance().getTime());
        ResPropertyValue.PropValue[] propValues = new ResPropertyValue.PropValue[propertyIdList.size()];

        for (int i = 0; i < SIZE; i++) {
            Long propId = propertyIdList.get(i);
            Property property = propertyCache.get(propId);
            if (property == null) {
                continue;
            }
            CollectField field = fieldCache.getByPropId(propId);
            PropValue propValue = ResPropertyValue.createPropValue(propId, propValueMap.get(propId).toString(), field.getFieldName());
            propValues[i] = propValue;
        }
        value.setValues(propValues);
        return value;
    }

}
